# list all .c files that need to be compiled into object and linked in xschem
put /local/src {
 icon.c callback.c actions.c move.c check.c clip.c draw.c globals.c
 main.c netlist.c hash_iterator.c findnet.c scheduler.c store.c xinit.c
 select.c font.c editprop.c save.c paste.c token.c psprint.c node_hash.c
 hilight.c options.c vhdl_netlist.c svgdraw.c spice_netlist.c
 tedax_netlist.c verilog_netlist.c parselabel.c expandlabel.c
 in_memory_undo.c cairo_jpg.c
}

# list all files that need to be installed in "$(XSHAREDIR)"
put /local/install_shares {
 keys.help xschem.help xschem.tcl break.awk convert_to_verilog2001.awk
 flatten.awk flatten_tedax.awk flatten_savenodes.awk make_sym.awk make_sym_lcc.awk
 symgen.awk order_labels.awk sort_labels.awk spice.awk tedax.awk verilog.awk
 vhdl.awk hspice_backannotate.tcl add_custom_menu.tcl create_graph.tcl
 add_custom_button.tcl change_index.tcl icon.xpm resources.tcl xschemrc
 ngspice_backannotate.tcl gschemtoxschem.awk traversal.tcl mouse_bindings.tcl
 place_sym_pins.tcl place_pins.tcl make_sch_from_spice.awk make_sym_from_spice.awk
}

# generate a list of objects from the list of source files
put /local/obj [@@/local/src@ @]
gsub /local/obj {\n} { }
gsub /local/obj {[.]c } {.o }

print [@
###############################################################
#  Generated by scconfig - DO NOT EDIT - will be overwritten  #
#  Source: Makefile.in; to regenerate run ./configure         #
###############################################################

ROOT = ..
OBJ = @/local/obj@

all: xschem rawtovcd

include $(ROOT)/Makefile.conf

rawtovcd: rawtovcd.o
	$(CC) -o  rawtovcd rawtovcd.o -lm

xschem: $(OBJ)
	$(CC) -o xschem $(OBJ) $(LDFLAGS)

parselabel.c: parselabel.l expandlabel.h
	flex -l -oparselabel.c  parselabel.l

expandlabel.c expandlabel.h: expandlabel.y
	bison -d -o expandlabel.c  expandlabel.y

parselabel.o: expandlabel.h

$(OBJ): xschem.h ../config.h Makefile

clean: FORCE
	rm -rf rawtovcd xschem *.o expandlabel.[ch] parselabel.c

# Explicit rule for each object:
@]

foreach /local/n in /local/src
	put /local/o /local/n
	sub /local/o {.c$} {.o}
	print [@
@/local/o@: @/local/n@
	$(CC) -c $(CFLAGS) -o @/local/o@ @/local/n@
@]
end
print [@
rawtovcd.o: rawtovcd.c
	$(CC) -c $(CFLAGS) -o rawtovcd.o rawtovcd.c
@]

print [@

install: xschem rawtovcd FORCE
	$(SCCBOX) mkdir -p "$(BINDIR)"
	$(SCCBOX) mkdir -p "$(XSHAREDIR)"
	$(SCCBOX) install -f xschem "$(BINDIR)"/xschem
	$(SCCBOX) install -f rawtovcd "$(BINDIR)"/rawtovcd
	$(SCCBOX) install -f -d systemlib/* "$(XSHAREDIR)"/systemlib @]

foreach /local/n in /local/install_shares
	print [@
	$(SCCBOX) install -f @/local/n@  "$(XSHAREDIR)"/@/local/n@ @]
end

print [@

distclean: clean

uninstall: FORCE
	$(SCCBOX) rm "$(BINDIR)"/xschem
	$(SCCBOX) rm "$(BINDIR)"/rawtovcd
	$(SCCBOX) rm "$(XSHAREDIR)"/systemlib/*@]

foreach /local/n in /local/install_shares
	print [@
	$(SCCBOX) rm "$(XSHAREDIR)"/@/local/n@ @]
end

print [@

FORCE:

@]
